﻿using System;

namespace b4
{
    class Program
    {
        class graph
        {
        double chang;
        double kuan;
        public double Chang { get => chang; set => chang = value; }
        public double Kuan { get => kuan; set => kuan = value; }

        public double GetCO()
        {
            return (this.Chang + this.Kuan) * 2;
        }
        public double GetSO()
        {
            return this.Chang * this.Kuan;
        }
    }

        class graph2
        {
            double bianchang;
            public double Chang { get => bianchang; set => bianchang = value; }
            public double GetCO()
            {
                return (this.Chang) * 4;
            }
            public double GetSO()
            {
                return this.Chang * this.Chang;
            }
        }

        class graph3
        {
            double bian1;
            double bian2;
            double bian3;
            public double Bian1 { get => bian1; set => bian1 = value; }
            public double Bian2 { get => bian2; set => bian2 = value; }
            public double Bian3 { get => bian3; set => bian3 = value; }

            public double GetCO()
            {
                return (this.Bian1 + this.Bian2+this.Bian3) ;
            }
            public double GetSO()
            {
                double p = (Bian1 + +Bian2 + Bian3) / 2;
                double m = p * (p - Bian1) * (p - Bian2) * (p - Bian3);
                System.Math.Sqrt(m);
                return System.Math.Sqrt(m);
            }
        }

        static void Main(string[] args)
        {
            Console.WriteLine("请输入图形（1长方形2正方形3三角形）");
            int x = Convert.ToInt32(Console.ReadLine());
            switch(x)
            {
                case 1:
                    graph c1 = new graph();
                    Console.WriteLine("请输入长的值:");
                    c1.Chang = Convert.ToDouble(Console.ReadLine());
                    Console.WriteLine("请输入宽的值:");
                    c1.Kuan = Convert.ToDouble(Console.ReadLine());
                    if (c1.Chang <= 0 || c1.Kuan <= 0)
                    {
                        Console.WriteLine("您输入的数据有误");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("周长为：{0}", c1.GetCO());
                        Console.WriteLine("面积为：{0}", c1.GetSO());
                        Console.ReadKey();
                        break;
                    }
                case 2:
                    graph2 c2 = new graph2();
                    Console.WriteLine("请输入边长的值:");
                    c2.Chang = Convert.ToDouble(Console.ReadLine());
                    if (c2.Chang <= 0)
                    {
                        Console.WriteLine("您输入的数据有误");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("周长为：{0}", c2.GetCO());
                        Console.WriteLine("面积为：{0}", c2.GetSO());
                        Console.ReadKey();
                        break;
                    }
                case 3:
                    graph3 c3 = new graph3();
                    Console.WriteLine("请输入第一个边长的值:");
                    c3.Bian1 = Convert.ToDouble(Console.ReadLine());
                    Console.WriteLine("请输入第二个边长的值:");
                    c3.Bian2 = Convert.ToDouble(Console.ReadLine());
                    Console.WriteLine("请输入第三个边长的值:");
                    c3.Bian3 = Convert.ToDouble(Console.ReadLine());
                    if (c3.Bian1 <= 0 || c3.Bian2 <= 0 || c3.Bian3 <= 0 || c3.Bian1 + c3.Bian2 <= c3.Bian3 || c3.Bian2 + c3.Bian3 <= c3.Bian1 || c3.Bian1 + c3.Bian3 <= c3.Bian2)
                    {
                        Console.WriteLine("您输入的数据有误");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("周长为：{0}", c3.GetCO());
                        Console.WriteLine("面积为：{0}", c3.GetSO());
                        Console.ReadKey();
                        break;
                    }
            }

        }
    }
}
